<?php

namespace Util;

class User
{

    /**
     * 加密密码.
     *
     * @param string $password 密码.
     *
     * @return string
     */
    public static function encodePassword($password) {
        $factor = 'abcedfgeee';
        return md5(md5($password) . $factor);
    }

    public static function getUserPhoto($photo, $width, $height) {
        if (!$photo) {
            return '/Resource/images/nohead_new.jpg';
        }
		if (strpos($photo, 'http') === 0) {
			return $photo;
		}
        $pathInfo = pathinfo($photo);
        $host = 'http://' . str_ireplace('admin', 'www', $_SERVER['HTTP_HOST']);
        $nowFile =  $host . '/' . $pathInfo['dirname'] . '/' . $pathInfo['filename'] . '_' . $width . '_' . $height . '.' . $pathInfo['extension'];
        return $nowFile;
    }

	public static function getOld($time, $d = '岁') {
		if ($time) {
			$one = date('Y.md', $time);
			$day = date('Y.md');
			echo (int) ($day - $one) . $d;
		}
	}

	public static function getUserPhotoRectangle($photo, $width) {
		$pathInfo = pathinfo($photo);
		$host = 'http://' . str_ireplace('admin', 'www', $_SERVER['HTTP_HOST']);
		$nowFile =  $host . '/' . $pathInfo['dirname'] . '/' . $pathInfo['filename'] . '_' . $width . '.' . $pathInfo['extension'];
		return $nowFile;
	}
}